<template>
  <div>
    <el-dialog
      title="信息编辑"
      :visible.sync="editVisible"
      width="40%"
      :show-close="false"
      :close-on-click-modal="false">

      <el-breadcrumb separator-class="el-icon-arrow-right" style="margin-top: 15px;margin-bottom: 30px;">
        <el-breadcrumb-item v-for="(item,index) in includeInfo" style="color: #13ce66" :key="index">{{item}}</el-breadcrumb-item>

      </el-breadcrumb>

      <el-breadcrumb separator="/" style="margin-bottom: 15px;">
        <el-breadcrumb-item v-for="(item,index) in includeNameInfo" :key="index">{{item}}</el-breadcrumb-item>
      </el-breadcrumb>


      <el-form ref="editFormData" :model="editFormData" :rules="editFormData_rules" label-width="80px">
        <el-form-item :label="names" prop="name">
          <el-input v-model="editFormData.name" size="small"></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
    <el-button @click="closeEdit" size="mini">取 消</el-button>
    <el-button type="primary" @click="update" size="mini">确 定</el-button>
  </span>
    </el-dialog>
  </div>
</template>
<script>
  import {editLevel,editGrade,editSubject} from '@/api/questions'
  export default{
    props:["isShowEditDialog","editData","editType","includeInfo","includeNameInfo"],
    mounted(){
      this.editFormData.name = this.editData.name;
      this.editFormData.id = this.editData.id;
      this.names = this.editName[this.editType];

    },
    data(){
      return {
        editFormData:{
            id:0,
            name:""
        },
        editVisible:this.isShowEditDialog,

        editName:["学历名称","年级名称","课目名称"],

        names:"",

        //编辑信息校验
        editFormData_rules:{
          name:[
            { required: true, message: '不能为空', trigger: 'change' },
          ]
        }
      }
    },
    methods:{
      closeEdit(){
          this.editVisible = false;
          if(this.editType == 0){
            this.$emit("closeEditDialog",0);
          }else if(this.editType == 1){
            this.$emit("closeEditDialog",1);
          }else if(this.editType == 2){
            this.$emit("closeEditDialog",2);
          }else{
            this.$emit("closeEditDialog",3);
          }

      },
      update(){
        this.$refs["editFormData"].validate((valid) => {
            if(valid){
              if(this.editType == 0){
                //编辑学历
                editLevel({l_id:this.editFormData.id,l_name:this.editFormData.name}).then(res=>{
                  if(res.code == 200){
                    this.$message({
                      type: 'success',
                      message: '编辑成功'
                    });
                    this.closeEdit();
                  }else{
                    this.$message({
                      type: 'error',
                      message: '编辑失败'
                    });
                  }
                });
              }else if(this.editType == 1){
                //编辑年级
                editGrade({g_id:this.editFormData.id,g_name:this.editFormData.name}).then(res=>{
                  if(res.code == 200){
                    this.$message({
                      type: 'success',
                      message: '编辑成功'
                    });
                    this.closeEdit();
                  }else{
                    this.$message({
                      type: 'error',
                      message: '编辑失败'
                    });
                  }
                });
              }else if(this.editType == 2){
                //编辑课目
                editSubject({sb_id:this.editFormData.id,sb_name:this.editFormData.name}).then(res=>{
                  if(res.code == 200){
                    this.$message({
                      type: 'success',
                      message: '编辑成功'
                    });
                    this.closeEdit();
                  }else{
                    this.$message({
                      type: 'error',
                      message: '编辑失败'
                    });
                  }
                });
              }
            }
        });
      }
    }
  }
</script>
